package testLayer;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import modelLayer.OrderLine;
import modelLayer.SalesOrder;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import controlLayer.OrderCtr;
import controlLayer.ProductCtr;

public class OrderCtrTest {
	private OrderCtr orderCtr;
	private String	 productName_fail,
					 productName_success,
					 customerName_fail,
					 customerName_success;
	private int      amount_fail,
				     amount_success,
				     productID_fail,
				     productID_success;

	@Before
	public void setUp() throws Exception {
		
		this.orderCtr = new OrderCtr();
		this.productName_fail = "hardbånd";
		this.productName_success = "armbånd";
		this.customerName_success = "Peter Jensen";
		this.customerName_fail = "Hank Schrader";
		this.amount_fail= 0;
		this.amount_success = 2;
		this.productID_fail = 0;
		this.productID_success = 1;

	}

	@After
	public void tearDown() throws Exception {
		
		
		
	}

	@Test
	public void testOrderCtr() {
		
		assertTrue(this.orderCtr != null && this.orderCtr.getCustomerCtr() != null && this.orderCtr.getProductCtr() != null);
		
	}

	@Test
	public void testCreateSale() {
		
		this.orderCtr.createSale();
		assertTrue(this.orderCtr.getSalesOrder() != null);
		
	}

	@Test
	public void testAddProductSuccess() {
		
		assertTrue(this.orderCtr.addProduct(this.productID_success, this.amount_success)!= null);
		
	}
	
	@Test
	public void testAddProductFail() {
		
		assertTrue(this.orderCtr.addProduct(this.productID_fail, this.amount_fail) == null);
		
	}

	@Test
	public void testRemoveOrderLine() {
		
		this.orderCtr.addProduct(this.productID_success, this.amount_success);
		assertTrue(orderCtr.removeOrderLine(this.productID_success));
		
	}

	@Test
	public void testAddCustomerSuccess() {
		
		this.orderCtr.addCustomer(this.customerName_success);
		assertEquals(this.customerName_success, this.orderCtr.getSalesOrder().getCustomer().getName());
		
	}
	
	@Test
	public void testAddCustomerFail() {
		
		this.orderCtr.addCustomer(this.customerName_fail);
		assertTrue(this.orderCtr.getSalesOrder().getCustomer() == null);
		
	}

	@Test
	public void testEndOrder() {
		
		fail("Not yet implemented");
		
	}

}
